package fun.sssdnsy.util;

import javafx.scene.image.Image;
import javax.imageio.ImageIO;
import java.io.*;

public class ImageUtil {

    public static byte[] imageToBytes(Image image) throws IOException {
        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
        ImageIO.write(javafx.embed.swing.SwingFXUtils.fromFXImage(image, null), "png", outputStream);
        return outputStream.toByteArray();
    }

    public static Image bytesToImage(byte[] bytes) {
        return new Image(new ByteArrayInputStream(bytes));
    }
}
